package facecat;
import facecat.topin.btn.*;
import facecat.topin.core.*;
import facecat.topin.chart.*;
import facecat.topin.div.*;
import java.util.*;
import facecat.topin.grid.*;
import facecat.topin.tab.*;
import example.*;
import org.w3c.dom.Node;

/*
* 主框架
*/
public class MainFrame extends UIXmlEx implements FCTouchEventCallBack
{
    public MainFrame() {
    }
    
    /** 
    创建控件
    @param node 节点
    @param type 类型
    @return 控件
   */
   @Override
   public FCView createView(Node node, String type)
   {
           FCNative inative = getNative();
           if (type.equals("layoutbutton"))
           {
                   return new LayoutButton();
           }
           else
           {
                   return super.createView(node, type);
           }
   }
    
    public String getXml(String name){
        String content = "";
        RefObject<String> refContent = new RefObject<String>(content);
        String dir = DataCenter.getAppPath() + DataCenter.m_seperator + "example" + DataCenter.m_seperator + name;
        FCFile.read(dir, refContent);
        return refContent.argvalue;
    }
    
    public LabelExample labelExample;
    public ButtonExample buttonExample;
    public CheckBoxExample checkBoxExample;
    public RadioButtonExample radioButtonExample;
    public TextBoxExample textBoxExample;
    public SpinExample spinExample;
    public ComboBoxExample comboBoxExample;
    public DatePickerExample dateTimePicker;
    public DivExample divExample;
    public LayoutDivExample layoutDivExample;
    public SplitLayoutDivExample splitLayoutDivExample;
    public GridExample gridExample;
    public TreeExample treeExample;
    public GroupBoxExample groupBoxExample;
    public TabViewExample tabViewExample;
    public CalendarExample calendarExample;
    public BlankExample blankExample;
    public MenuExample menuExample;
    public PaintExample paintExample;
    
    /*
    * 加载XML
    */
   public void loadXml(String xml, FCView parent) {
        super.loadXml(xml, null);
         FCLayoutDiv layoutDiv = getLayoutDiv("divLayout");
        for (int i = 0; i < layoutDiv.m_views.size(); i++)
        {
            FCView view = layoutDiv.m_views.get(i);
            if (view.getName().indexOf("LayoutButton") == 0)
            {
                view.addEvent(this, FCEventID.Click, this);
            }
        }
        labelExample = new LabelExample();
        labelExample.setNative(getNative());
        labelExample.loadXml(getXml("LabelExample.xml"), getTabPage("TabPage"));
        buttonExample = new ButtonExample();
        buttonExample.setNative(getNative());
        buttonExample.loadXml(getXml("ButtonExample.xml"), getTabPage("TabPage2"));
        checkBoxExample = new CheckBoxExample();
        checkBoxExample.setNative(getNative());
        checkBoxExample.loadXml(getXml("CheckBoxExample.xml"), getTabPage("TabPage3"));
        radioButtonExample = new RadioButtonExample();
        radioButtonExample.setNative(getNative());
        radioButtonExample.loadXml(getXml("RadioButtonExample.xml"), getTabPage("TabPage4"));
        textBoxExample = new TextBoxExample();
        textBoxExample.setNative(getNative());
        textBoxExample.loadXml(getXml("TextBoxExample.xml"), getTabPage("TabPage5"));
        spinExample = new SpinExample();
        spinExample.setNative(getNative());
        spinExample.loadXml(getXml("SpinExample.xml"), getTabPage("TabPage6"));
        comboBoxExample = new ComboBoxExample();
        comboBoxExample.setNative(getNative());
        comboBoxExample.loadXml(getXml("ComboBoxExample.xml"), getTabPage("TabPage7"));
        dateTimePicker = new DatePickerExample();
        dateTimePicker.setNative(getNative());
        dateTimePicker.loadXml(getXml("DatePickerExample.xml"), getTabPage("TabPage8"));
        divExample = new DivExample();
        divExample.setNative(getNative());
        divExample.loadXml(getXml("DivExample.xml"), getTabPage("TabPage9"));
        layoutDivExample = new LayoutDivExample();
        layoutDivExample.setNative(getNative());
        layoutDivExample.loadXml(getXml("LayoutDivExample.xml"), getTabPage("TabPage10"));
        splitLayoutDivExample = new SplitLayoutDivExample();
        splitLayoutDivExample.setNative(getNative());
        splitLayoutDivExample.loadXml(getXml("SplitLayoutDivExample.xml"), getTabPage("TabPage11"));
        gridExample = new GridExample();
        gridExample.setNative(getNative());
        gridExample.loadXml(getXml("GridExample.xml"), getTabPage("TabPage12"));
        treeExample = new TreeExample();
        treeExample.setNative(getNative());
        treeExample.loadXml(getXml("TreeExample.xml"), getTabPage("TabPage13"));
        groupBoxExample = new GroupBoxExample();
        groupBoxExample.setNative(getNative());
        groupBoxExample.loadXml(getXml("GroupBoxExample.xml"), getTabPage("TabPage14"));
        tabViewExample = new TabViewExample();
        tabViewExample.setNative(getNative());
        tabViewExample.loadXml(getXml("TabViewExample.xml"), getTabPage("TabPage16"));
        calendarExample = new CalendarExample();
        calendarExample.setNative(getNative());
        calendarExample.loadXml(getXml("CalendarExample.xml"), getTabPage("TabPage17"));
        blankExample = new BlankExample();
        blankExample.setNative(getNative());
        blankExample.loadXml(getXml("BlankExample.xml"), getTabPage("TabPage18"));
        menuExample = new MenuExample();
        menuExample.setNative(getNative());
        menuExample.loadXml(getXml("MenuExample.xml"), getTabPage("TabPage19"));
        paintExample = new PaintExample();
        paintExample.setNative(getNative());
        paintExample.loadXml(getXml("PaintExample.xml"), getTabPage("TabPage20"));
    }
   
    /*
    * 点击事件
    * @param eventName 事件ID
    * @param sender 发送者
    * @param touchInfo 触摸信息
    * @param invoke 引用者
    */
    public void callTouchEvent(String eventName, Object sender, FCTouchInfo touchInfo, Object invoke)
    {
        FCView view = (FCView)sender ;
        if (view.getName().indexOf("LayoutButton") == 0)
        {
            FCTabView tabView = getTabView("tabContent");
            tabView.setSelectedIndex(FCTran.strToInt(view.getName().replace("LayoutButton", "")) - 1);
            tabView.update();
            tabView.invalidate();
        }
    }
}
